<template>
	<view>
		<modules v-if="PageCur=='modules'"></modules>
		<info v-if="PageCur=='infos'"></info>
		<person v-if="PageCur=='persons'"></person>
		<view class="cu-bar tabbar bg-white shadow foot">
			<view class="action" @click="NavChange" data-cur="modules">
				<view :class="['tab-icon-block', PageCur == 'modules'?'bg-blue':'bg-white']">
					<text :class="['ph-zhuye', 'font-size34', PageCur == 'modules'?'text-white':'text-gray']"></text>
				</view>
				<view :class="PageCur=='modules'?'text-blue':'text-gray'">首页</view>
			</view>
			<view class="action" @click="NavChange" data-cur="infos">
				<view :class="['tab-icon-block', PageCur == 'infos'?'bg-blue':'bg-white']">
					<text :class="['ph-xiaoxi', 'font-size34', PageCur == 'infos'?'text-white':'text-gray']"></text>
				</view>
				<view :class="PageCur=='infos'?'text-blue':'text-gray'">信息</view>
			</view>
			<view class="action" @click="NavChange" data-cur="persons">
				<view :class="['tab-icon-block', PageCur == 'persons'?'bg-blue':'bg-white']">
					<text :class="['ph-wode', 'font-size34', PageCur == 'persons'?'text-white':'text-gray']"></text>
				</view>
				<view :class="PageCur=='persons'?'text-blue':'text-gray'">我的</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { post } from "../../lib/Util.js"
	export default {
		data() {
			return {
				PageCur: 'modules',
			}
		},
		onShow() {
			// #ifdef APP-PLUS
				plus.screen.unlockOrientation();//解除锁定屏幕方向
				plus.screen.lockOrientation('portrait-primary');
			// #endif
		},
		onLoad(options) {
			if(options.type) {
				this.PageCur = options.type
			}
			this.updataUserInfo()
		},
		methods: {
			NavChange: function(e) {
				this.PageCur = e.currentTarget.dataset.cur
			},
			// 更新用户信息
			async updataUserInfo() {
				var cid = null
				// #ifdef APP-PLUS
				let pinf = plus.push.getClientInfo();
				cid = pinf.clientid; //客户端标识
				// #endif
				const data = {
					username: uni.getStorageSync('user').user.username,
					password: uni.getStorageSync('user').user.password,
					clientId: cid || 111
				};
				let res = await post("/app/login", data)
				if(res.code === 0){
						this.$store.commit('login', res)
				}else{
					uni.showToast({
						icon: 'none',
						title: '身份信息不匹配，请重新登录'
					});
					setTimeout(()=> {
						this.$store.commit('logout')
						uni.reLaunch({
							url: '/pages/login/login'
						})
					}, 1500)
				}
			}
		}
	}
</script>

<style>
</style>
